import logging
import os
from logging import handlers


def initLogging(file_name):
    level = logging.ERROR
    if os.environ.has_key('QAGENT_DEBUG'):
        level = logging.DEBUG
    hdlr = handlers.RotatingFileHandler(filename = file_name,
                                        mode='a',
                                        maxBytes=50000,
                                        backupCount=3)
    fmts='%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
    dfmt='%Y-%m-%d %H:%M:%S'
    fmt = logging.Formatter(fmts, dfmt)
    hdlr.setFormatter(fmt)
    logging.root.addHandler(hdlr)
    logging.root.setLevel(level)
    logInit = True

